package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.pojo.Address;
import com.itheima.service.AddressService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/address")
public class AddressController {
    @Reference
    private AddressService addressService;

    @RequestMapping("/getMap")
    public Result getMap(){
        try{
            List<Address> list = addressService.findAll();
            return new Result(true,"查找地址成功",list);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"查找地址失败");
        }
    }
    @RequestMapping("/findById")
    public Result findById(Integer addressId){
        try{
            System.out.println(addressId);
            Address byId = addressService.findById(addressId);
            return new Result(true,"查找地址成功",byId);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"查找地址失败");
        }
    }

}
